package org.example.queue;

import java.util.Stack;

/**
 * @author liyishan
 * @date 2024/10/9 16:22
 * @apiNote
 */

public class QueueByStack<T> {
    private Stack<T> stackIn;
    private Stack<T> stackOut;
    public QueueByStack() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }
    public boolean isEmpty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }
    public void offer(T data) {
        stackIn.push(data);
    }

    public T poll(){
        if(stackOut.isEmpty()){
            while(!stackIn.isEmpty()){
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.pop();
    }
}
